// version 2020/05/23
#ifndef _PROCREQ_H_
#define _PROCREQ_H_

#include "defines.h"
#include "strlib.h"

//#define test // env: x86_64 linux gcc

#define preMemSize 65536 // 64KB 

typedef struct {
    u32 size;   // filesize, bytes
    u8 *data; // file data
} file;

#define indexPage "rulerPage.html"
#define page404 "<div style=\"padding:48px;\"><div style=\"word-break:break-word;font-weight:600;font-size:36px;\">404 Not Found</div></div>"
    
// outside ================================//
#ifdef test
    #include <stdio.h>
    #include <malloc.h>
    #define root "."
    #define mmalloc(size) malloc(size)
    #define mfree(pointer) free(pointer)
    #define FIL FILE
    #define lcdPrint(x, y, size, str) printf("%s\n", str)
    #define f_open(readStream, filename, FA_READ)  readStream = fopen(filename, "rb")
    #define getFileSize(fileSize, readStream) fseek(readStream, 0, SEEK_END); *fileSize = ftell(readStream); rewind(readStream)
    #define f_read(readStream, fileBuffer, fileSize, status) *status = fread(fileBuffer, 1, fileSize, readStream)
    #define f_close(readStream) fclose(readStream)
#else
    #include "ff.h"
    #include "lcd.h"
    #include "malloc.h"
    #define root "0:"
    #define mmalloc(size) Mem_malloc(1,size)
    #define mfree(pointer) Mem_free(1,pointer)
    #define lcdPrint(x, y, size, str) LCD_DisplayString(x, y, size, str)
    #define getFileSize(fileSize, readStream) *fileSize = readStream->fsize
#endif

info *preInfo(info *data);
message *preRequest(message *request);
message *procReq(message *request, message *response, info *inf);

#endif
